using System;
using System.Collections.Generic;
using SimpleJSON;
using UnityEngine;

namespace Gj.DarkLoong
{
    public class Follow
    {

        public static void List(int page, int size,
            Action<JSONObject, string> callback)
        {
            Project.ProjectUpdate.Queue.Enqueue(async () =>
            {
                var data = new JSONObject();
                data["page"] = page;
                data["size"] = size;
                var header = Api.CookieHeader();
                header["token"] = Auth.SessionToken;
                var response = await Api.Get($"/workshop/follow/list", data,
                    header);
                var err = response["status"].AsInt != 200 ? response["message"].Value : "";
                var item = response["result"].AsObject;
                callback(item, err);
            });
        }

        public static void Do(string id, string action, Action<bool, string> callback)
        {
            Project.ProjectUpdate.Queue.Enqueue(async () =>
            {
                Debug.Log($"follow: {id} {action}");
                var data = new JSONObject();
                data["action"] = action;
                var header = Api.CookieHeader();
                header["token"] = Auth.SessionToken;
                var response = await Api.Put($"/workshop/follow/{id}", data,
                    header);
                var err = response["status"].AsInt != 200 ? response["message"].Value : "";
                var item = response["result"].AsBool;
                callback(item, err);
            });
        }
    }
}